package edu.hunau.cxb18.orm.mapper;

import edu.hunau.cxb18.orm.mapper.provide.ProductSqlProvide;
import edu.hunau.cxb18.orm.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author hb
 * @create 2020-03-04 10:18
 */
public interface ProductMapper {

    @Insert("insert into t_product(name,pdesc,pic,price,stock) values (#{name},#{pdesc},#{pic},#{price},#{stock})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    public void insertProduct(Product product);


    //@InsertProvider(type= ProductSqlProvide.class,method="insertProductByList")
    @Insert("<script>" +
            " insert into t_product(name,pdesc,pic,price,stock) values " +
            "<foreach item='pro' collection='pros' separator=','>" +
            " (#{pro.name},#{pro.pdesc},#{pro.pic},#{pro.price},#{pro.stock})"+
            "</foreach>" +
            "</script>")
    public void insertProducts(@Param("pros") List<Product> pros);

    /**
     * 根据商品名称或者商品的描述进行模糊查询
     * @param datas
     * @return
     */
    //@Select("<script> </script>")
    @SelectProvider(type= ProductSqlProvide.class,method="queryByLikeDataSQL")
    public List<Product> queryByLikeData(Map<String,String> datas);
}
